package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.li.interfaces.OnItemClickListener;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.AgentInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/10/24 0024
 * Description: 区代列表适配器
 */

public class AgentAdapter extends RecyclerView.Adapter<AgentAdapter.AgentHolder> {



    private LayoutInflater mInflater;
    private List<AgentInfo> mAgentInfoList;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        mOnItemClickListener = onItemClickListener;
    }

    private OnItemClickListener mOnItemClickListener;
    public AgentAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public AgentHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_agent, parent, false);
        final AgentHolder holder=new AgentHolder(view);
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.onItemClick(v,holder.getLayoutPosition());
                }
            });
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(AgentHolder holder, int position) {
        AgentInfo info=mAgentInfoList.get(position);
        holder.mTxtName.setTxtRight(info.getRealname());
        holder.mTxtAgentName.setTxtRight(info.getArea());
        holder.mTxtMobile.setTxtRight(info.getMobile());

    }

    @Override
    public int getItemCount() {
        return mAgentInfoList == null ? 0 : mAgentInfoList.size();
    }

    public void setAgentInfoList(List<AgentInfo> agentInfoList) {
        mAgentInfoList = agentInfoList;
        notifyDataSetChanged();
    }

    static class AgentHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_agent_name)
        DoubleTextView mTxtAgentName;
        @BindView(R.id.txt_name)
        DoubleTextView mTxtName;
        @BindView(R.id.txt_mobile)
        DoubleTextView mTxtMobile;
        public AgentHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
